#include "Weapon.h"

// Constructor
CWeapon::CWeapon(void)
: sprite_anim_start		( 0 )
, sprite_anim_end		( 0 )
, animation_interval	( 1000 )
, animation_play		( false )
, stats_level			( 1 )
, stats_damage			( 1.0f )
, stats_damage_do		( 1.0f )
, stats_damage_modifier	( 1.0f )
, stats_attackinterval	( 1000 )
, type_id				( DUALSWORD )
{
}

// Destructor
CWeapon::~CWeapon(void)
{
}

// Set SpriteAnimation Interval
void CWeapon::SetSpriteAnimationInterval(const int animation_interval)
{
	this->animation_interval = animation_interval;
}

// Set Level
void CWeapon::SetLevel(const int level)
{
	// Set Level
	this->stats_level = level;

	// New Damage
	this->SetAttackDamage( stats_damage );
}

// Set Attack Damage
void CWeapon::SetAttackDamage(const float attack_damage)
{
	this->stats_damage = attack_damage + ( ( stats_level - 1 ) * stats_damage_modifier );
}

// Set Attack Damage Modifier
void CWeapon::SetAttackDamageModifier(const float attack_damage_modifier)
{
	this->stats_damage_modifier = attack_damage_modifier;
}

// Set Attack Speed
void CWeapon::SetAttackSpeed(const int attack_speed)
{
	this->stats_attackinterval = attack_speed;
}

// Get Sprite Animation Start Image Number
int CWeapon::GetSpriteAnimationStart(void)
{
	return this->sprite_anim_start;
}

// Get Sprite Animation End Image Number
int CWeapon::GetSpriteAnimationEnd(void)
{
	return this->sprite_anim_end;
}

// Get Sprite Animation Interval
int CWeapon::GetSpriteAnimationInterval(void)
{
	return this->animation_interval;
}

// Get Sprite Animation Play
bool CWeapon::GetSpriteAnimationPlay(void)
{
	return this->animation_play;
}

// Get Level
int CWeapon::GetLevel(void)
{
	return this->stats_level;
}

// Get Attack Damage
float CWeapon::GetAttackDamage(void)
{
	return this->stats_damage;
}

// Get Attack Damage Attack
float CWeapon::GetAttackDamageAttack(void)
{
	return this->stats_damage_do;
}

// Get Attack Damage Modifier
float CWeapon::GetAttackDamageModifier(void)
{
	return this->stats_damage_modifier;
}

// Get Attack Speed
int CWeapon::GetAttackSpeed(void)
{
	return this->stats_attackinterval;
}

// Get Weapon Type ID
CWeapon::WEAPON CWeapon::GetWeaponTypeID(void)
{
	return this->type_id;
}

// Check If Attacking
bool CWeapon::CheckIfAttacking(void)
{
	return this->animation_play;
}

// Check Whether Attack Delay Timer Has Ended
bool CWeapon::CheckAttackDelayEnd(void)
{
	return this->timer_attackdelay.CheckIfTimerEnd();
}

// Weapon Level Up
void CWeapon::DoLevelUpWeapon(const int how_many_level)
{
	// Level Up
	this->stats_level += how_many_level;

	// New Damage
	this->SetAttackDamage( stats_damage );
}

// Reset Weapon
void CWeapon::ResetWeapon(void)
{
	// Reset Animation
	this->animation_play = false;
	this->SetSpriteImageNumber( sprite_anim_start );
}

// Attack Interval End
void CWeapon::AttackEndInterval(void)
{
	// End Attack Delay Counter
	this->timer_attackdelay.StopTimer();
}

// Attack End
void CWeapon::AttackEnd(void)
{
	// Start Attack Delay Counter
	this->timer_attackdelay.StartTimer( 0, 0, 0, stats_attackinterval );
}

// Primary Attack
void CWeapon::AttackPrimaryAttack(void)
{
	// Wait For Attack Delay
	if ( CheckAttackDelayEnd() )
	{
		// Reset Weapon
		this->ResetWeapon();

		// Set Damage
		this->stats_damage_do = stats_damage;

		// Do Animation
		this->animation_play = true;
	}
}

// Secondary Attack
void CWeapon::AttackSecondaryAttack(void)
{
	// Wait For Attack Delay
	if ( CheckAttackDelayEnd() )
	{
		// Reset Weapon
		this->ResetWeapon();

		// Set Damage
		this->stats_damage_do = 0.0f;

		// Do Animation
		this->animation_play = true;
	}
}

// Initialise
void CWeapon::Initialise(const int SIZE_X, const int SIZE_Y, const int animation_interval, const int level, const float attack_damage, const float attack_damage_modifier, const int attack_speed)
{
	// Set Data
	this->SetSpriteAnimationInterval	( animation_interval );
	this->SetLevel						( level );
	this->SetAttackDamage				( attack_damage );
	this->SetAttackSpeed				( attack_speed );
	this->SetAttackDamageModifier		( attack_damage_modifier );

	// Size
	this->Init( Vector3D( 0.0f, 0.0f, 0.0f ), SIZE_X, SIZE_Y );

	// Set On Ground
	this->SetOnGround( true );

	// Allow Offset
	this->letOffset = true;

	// Weapon Can't Move
	this->SetSpeed( 0.0f );
}

// Update Object
void CWeapon::UpdateObject(float elapsed)
{
	// Play Animation
	if ( animation_play )
	{
		// Play Animation
		this->PlaySpriteAnimation( sprite_anim_start, sprite_anim_end, animation_interval );

		// Check For Animation End
		if ( animationFinished ) this->ResetWeapon();
	}

	// Update Object
	Object::UpdateObject( Vector3D(), elapsed );

	// Update Attack Delay
	timer_attackdelay.UpdateTimer();
}

// Render Object
void CWeapon::RenderObject(void)
{
	if ( animation_play ) Object::RenderObject();
}